/*
 * This file is part of TradeHelper library.
 *
 * TradeHelper library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TradeHelper library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TradeHelper library.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.rag.core;

import com.rag.managers.RagManager;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * User: mgarin Date: 04.04.12 Time: 17:02
 */

@XStreamAlias( "ItemData" )
public class ItemData implements Serializable
{
    @XStreamAsAttribute
    private String userId;

    @XStreamAsAttribute
    private Integer refineRate;

    @XStreamAsAttribute
    private String itemId;

    @XStreamAsAttribute
    private Integer slotCount;

    @XStreamImplicit( itemFieldName = "card" )
    private List<String> cardIds;

    // Parsing time data
    private transient boolean identified;
    private transient boolean foundInner;
    private transient List<String> possibleItemIds;
    private transient Map<Integer, List<String>> possibleCardIds;


    public ItemData ()
    {
        super ();
        identified = false;
        foundInner = false;
    }

    public boolean isIdentified ()
    {
        return identified;
    }

    public void setIdentified ( boolean identified )
    {
        this.identified = identified;
    }

    public boolean isFoundInner ()
    {
        return foundInner;
    }

    public void setFoundInner ( boolean foundInner )
    {
        this.foundInner = foundInner;
    }

    public String getUserId ()
    {
        return userId;
    }

    public void setUserId ( String userId )
    {
        this.userId = userId;
    }

    public String getItemId ()
    {
        return itemId;
    }

    public void setItemId ( String itemId )
    {
        this.itemId = itemId;
    }

    public List<String> getPossibleItemIds ()
    {
        return possibleItemIds;
    }

    public void setPossibleItemIds ( List<String> possibleItemIds )
    {
        this.possibleItemIds = possibleItemIds;
    }

    public Integer getRefineRate ()
    {
        return refineRate;
    }

    public void setRefineRate ( Integer refineRate )
    {
        this.refineRate = refineRate;
    }

    public Integer getSlotCount ()
    {
        return slotCount;
    }

    public void setSlotCount ( Integer slotCount )
    {
        this.slotCount = slotCount;
    }

    public List<String> getCardIds ()
    {
        return cardIds;
    }

    public void setCardIds ( List<String> cardIds )
    {
        this.cardIds = cardIds;
    }

    public void addCardId ( String cardId )
    {
        this.cardIds.add ( cardId );
    }

    public Map<Integer, List<String>> getPossibleCardIds ()
    {
        return possibleCardIds;
    }

    public void setPossibleCardIds ( Map<Integer, List<String>> possibleCardIds )
    {
        this.possibleCardIds = possibleCardIds;
    }

    public ItemData clone ()
    {
        ItemData cloned = new ItemData ();
        cloned.setUserId ( getUserId () );
        cloned.setItemId ( getItemId () );
        cloned.setRefineRate ( getRefineRate () );
        cloned.setSlotCount ( getSlotCount () );

        if ( getCardIds () != null )
        {
            List<String> cardIds = new ArrayList<String> ();
            cardIds.addAll ( getCardIds () );
            cloned.setCardIds ( cardIds );
        }
        else
        {
            cloned.setCardIds ( null );
        }

        return cloned;
    }

    /**
     * Дополнительные методы
     */

    public Item getItem ()
    {
        return RagManager.getItem ( getItemId () );
    }

    public List<Item> getCards ()
    {
        return RagManager.getItems ( getCardIds () );
    }
}